<?php
require_once '../libs/app.config.php';
session_start();
if($_SESSION['LoginId'] == false){
	header("Location:login.php");
}

	//添加
	if($_GET['act']=='add')
	{
		$add=array("id"=>$id,
				   "position_name"=>$position_name,
				   "adv_width"=>$adv_width,
				   "adv_height"=>$adv_height,
				   "position_desc"=>$position_desc
				   );

		$result=$tpm->insert("adv_position",$add);
		if($result>0)
		echo "<script>alert('Add successfully!');location.href=('adv_position_list.php');</script>";
	}
	//修改
	if($id!="")
	{

$sql1="select * from adv_position where id='".$_GET['id']."'";
$query1=$tpm->query($sql1);
$rows=$tpm->fetch_array($query1);
$list=array("position_name"=>$rows['position_name'],
			"adv_width"=>$rows['adv_width'],
			"adv_height"=>$rows['adv_height'],
			"position_desc"=>$rows['position_desc'] );
	}

if($_POST['submit']){
if($_GET['act']=='edit')
{
	$update=array("position_name"=>$_POST['position_name'],
				  "adv_width"=>$_POST['adv_width'],
				  "adv_height"=>$_POST['adv_height'],
				  "position_desc"=>$_POST['position_desc']
				  );
	$where="id='".$_POST['id']."'";
$result=$tpm->update("adv_position",$update,$where);
if($result>0)
echo "<script>alert('Edit successfully!');location.href=('adv_position_list.php');</script>";
}
}

require_once(INCLUDE_PATH.'template.inc.php');  //模板类及对象$tpl的加载
$tpl->assign("list",$list);
$tpl->assign("id",$id);
$tpl->assign("msg",$msg);
$tpl->assign("show",$show);
$tpl->display("adv_position_add.html");
?>

